<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
	//查询住院药占比
	String yydm =  input.getDesc("yydm","01");//医院代码
	String ksdm = input.getDesc("ksdm","-1"); //传入科室代码代表该科室主任
	String date = input.getDesc("start_date","2018-01-28");//开始时间
	String endDa = input.getDesc("end_date","2018-01-28");//结束时间

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
	String nowDate = sdf2.format(sdf.parse(date));
	String nowEndDa = sdf2.format(sdf.parse(endDa));
	
	String startDate = nowDate+"00:00:00";
	String endDate = nowEndDa+"23:59:59";

	String sqlWhere = " and m.zxrq > '"+ startDate + "' and m.zxrq < '" + endDate+"' " ;
	if(!yydm.equals("-1"))
	sqlWhere += " and m.ksdm in (select new map (id as id) from his_dept where yjks_id != 1010 and yydm ='"+yydm+"') " ;
	if(!"-1".equals(ksdm)){
		sqlWhere += " and m.ksdm in( " + ksdm + ")";
	}
	//住院药占比

	List<Map> feelist = QBuilder.db("basedb").queryHql("select new map( m.zje as zje ,m.dxmdm as ypbz ) from ZY_BRFYMXK m   where  m.jlzt in(0,2)  " + sqlWhere+ " ");

	double ypmoney = 0;
	double sumMoney = 0;
	for(Map map : feelist ){
		double moneyTemp = Double.parseDouble(map.get("zje").toString());
		int ypbz = Integer.parseInt(map.get("ypbz") == null ? "0" : map.get("ypbz").toString());
		sumMoney += moneyTemp;
		if(ypbz == 1 ||  ypbz == 2 || ypbz == 3){
			ypmoney += moneyTemp;
		}
	}
	sumMoney = sumMoney == 0 ? 1 :sumMoney ;
	DecimalFormat df = new DecimalFormat("######0.00"); 
	double money = (ypmoney/sumMoney)*100;
	Map<String,Object> ma = new HashMap<String,Object>();
	Map<String,Object> ma1 = new HashMap<String,Object>();
	ma.put("sumCount",df.format(money));
	ma1.put("data",ma);
	Message msg = new Message();

	msg.put("errcode",0);
	msg.put("zy_charge_ratio",ma1);

	out.println(msg);
%>